﻿#include<stdio.h>
#include<stdlib.h>
#include"list.h"
void Showmovies(Item itme);
int main(){
	List movies;
	Item temp;
	InitializeList(&movies);
	if (ListIsFull(&movies))
	{
		fprintf(stderr, "No memoy availble! Bye!\n");
		exit(1);
	}
	puts("Enter first movie title:");
	while (gets(temp.title) != NULL&&temp.title[0] != '\0'){
		puts("Enter your rating <0-10>:");
		scanf("%d", &temp.rating);
		while (getchar() != '\n')
			continue;
		if (AddItem(temp, &movies) == false)
		{
			fprintf(stderr, "Problem allocating memory\n");
			break;
		}
		if (ListIsFull(&movies))
		{
			puts("The list is now full");
			break;
		}
		puts("Enter next movie titile (empty line to stop)");
	}

	if (ListIsEmpty(&movies))
		puts("No date entered.");
	else
	{
		puts("Here is the movie list:");
		Traverse(&movies, Showmovies);
	}
	printf("You enter %d movies.\n", ListItemCount(&movies));
	EmptyTheList(&movies);
	puts("Bye!");
	system("pause");
	return 0;
}
void Showmovies(Item item)
{
	printf("Movie: %s Rating: %d\n", item.title, item.rating);
}